//
//  NSObject+CommonClass.m
//  AoJi
//
//  Created by MinwenYi on 15-1-27.
//  Copyright (c) 2015年 xuanheng. All rights reserved.
//

#import "NSObject+CommonClass.h"

@implementation NSObject (CommonClass)
-(NSURL*)getPicUrl:(NSString*)str
{

return [NSURL URLWithString:[NSString stringWithFormat:@"http://cent.dsgrd.com/%@",str]];

}

-(UIColor*)getCorlor:(NSString*)colorStr
{
    
    float red=0;
    float green=0;
    float blue=0;
    
    int tem=0;
    for (int i=0; i<6; i++) {
        
        NSString *temstr=[colorStr substringWithRange:NSMakeRange(i, 1)];
        if ([temstr isEqualToString:@"A"]||[temstr isEqualToString:@"a"]) {
            temstr=@"10";
        }else if ([temstr isEqualToString:@"B"]||[temstr isEqualToString:@"b"]) {
            temstr=@"11";
        }else if ([temstr isEqualToString:@"C"]||[temstr isEqualToString:@"c"]) {
            temstr=@"12";
        }else if ([temstr isEqualToString:@"D"]||[temstr isEqualToString:@"d"]) {
            temstr=@"13";
        }else if ([temstr isEqualToString:@"E"]||[temstr isEqualToString:@"e"]) {
            temstr=@"14";
        }else if ([temstr isEqualToString:@"F"]||[temstr isEqualToString:@"f"]) {
            temstr=@"15";
        }
        
        tem=[temstr intValue];
        if (i<2) {
            
            if (i%2==0) {
                red=tem*16;
            }else{
                red+=tem;
            }
        
        }else if (i>1&&i<4)
        {
            
            if (i%2==0) {
                green=tem*16;
            }else{
                green+=tem;
            }
            
        }else if (i>=4)
        {
            
            if (i%2==0) {
                blue=tem*16;
            }else{
                blue+=tem;
            }
            
        }

        
        
    }
    
    return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1];

}

-(NSString*)getTime:(NSString*)str
{
    int num=[str doubleValue];
    NSDateFormatter *outputFormatter=[[NSDateFormatter alloc]init];
    [outputFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:num];
    
    
    return [outputFormatter stringFromDate:date];
    
}

- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    UIGraphicsBeginImageContext(size);
    // 绘制改变大小的图片
    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
    // 从当前context中创建一个改变大小后的图片
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    // 返回新的改变大小后的图片
    return scaledImage;
}
-(CGFloat)convertpx:(int)nums{
    return nums/96*72.0;
}
@end
